package logic

import (
	"context"
	"shopes/srv/shop"

	"shopes/api/internal/svc"
	"shopes/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type OrderAddLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewOrderAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *OrderAddLogic {
	return &OrderAddLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *OrderAddLogic) OrderAdd(req *types.OrderAddRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	userId := 1
	add, err := l.svcCtx.ShopRpc.OrderAdd(l.ctx, &shop.OrderAddRequest{
		UserId: int64(userId),
		Status: int64(req.Status),
		GoodId: int64(req.GoodId),
	})
	if err != nil {
		return &types.Response{
			Msg:  err.Error(),
			Code: 500,
			Data: nil,
		}, nil
	}
	return &types.Response{
		Msg:  "订单创建成功",
		Code: 200,
		Data: add,
	}, nil
}
